/**
 * Creat with IntelliJ IDEA
 * Description
 * User: mamba24
 * Date: 2022-07-26
 * Time: 20:33
 * To BE A Better Person-2020-3-2
 */
class counter{
    public int count;
   public void increas(){
       synchronized (this){
           count++;
       }

    }
}
public class TestDemo_Synchronsized {

    public static void main(String[] args)  {
        counter c=new counter();
        Thread t1=new Thread(()->{
            for (int i = 0; i < 50000; i++) {
                c.increas();
            }
        });
        Thread t2=new Thread(()->{
            for (int i = 0; i < 50000; i++) {
                c.increas();
            }
        });
        t1.start();
        t2.start();
        try {
            t1.join();
            t2.join();
        }catch (InterruptedException e){
            e.printStackTrace();
        }

        System.out.println(c.count);
    }
}
